﻿<?php
require_once(dirname(__FILE__) . '/../lanceur_spip.php');
include_spip('functions/pdk_common');
include_spip('classes/pdk_validation');

class TestClass_pdk_Validation extends SpipTest {
    /**
     * pdk_Validation
     */
    //private $validation;
    
    /**
     *  Some operations before all tests
     */
	function __construct() {        
        //$this->validation = pdk_load_class('pdk_validation', 'classes');		
    }
    
    /**
     *  Run before each test
     */
    function setUp() {
        
    }
    
    /**
     *  Run after each test
     */
    function tearDown() {
        
    }
    
    /**
     *  Some operations after all tests
     */
	function __destruct() {        
    }
	
	function Test_alpha() {
		$rules = array(
               array(
                     'field'   => 'test_field',
                     'label'   => 'Test',
                     'rules'   => 'alpha'
                  )
            );			
		
		// Work with latin symbols
		$validation = new pdk_Validation($rules);
		$this->assertTrue($validation->Validate(array('test_field'=>'abc')));
		$validation = new pdk_Validation($rules);
		$this->assertFalse($validation->Validate(array('test_field'=>'abc123')));
		 
		// Work with cyrilic symbols
		$validation = new pdk_Validation($rules);
		$this->assertTrue($validation->Validate(array('test_field'=>'абв')));
		$validation = new pdk_Validation($rules);
		$this->assertFalse($validation->Validate(array('test_field'=>'абв123')));
	}
	
	function Test_alpha_numeric() {
		$rules = array(
               array(
                     'field'   => 'test_field',
                     'label'   => 'Test',
                     'rules'   => 'alpha_numeric'
                  )
            );
			
		// Work with latin symbols
		$validation = new pdk_Validation($rules);
		$this->assertTrue($validation->Validate(array('test_field'=>'abc123')));
		$validation = new pdk_Validation($rules);
		$this->assertFalse($validation->Validate(array('test_field'=>'abc123!_~')));
		 
		// Work with cyrilic symbols
		$validation = new pdk_Validation($rules);
		$this->assertTrue($validation->Validate(array('test_field'=>'абв123')));
		$validation = new pdk_Validation($rules);
		$this->assertFalse($validation->Validate(array('test_field'=>'~абв123')));		
	}
	
	function Test_alpha_dash() {
		$rules = array(
               array(
                     'field'   => 'test_field',
                     'label'   => 'Test',
                     'rules'   => 'alpha_dash'
                  )
            );
			
		// Work with latin symbols
		$validation = new pdk_Validation($rules);
		$this->assertTrue($validation->Validate(array('test_field'=>'abc123-_')));
		$validation = new pdk_Validation($rules);
		$this->assertFalse($validation->Validate(array('test_field'=>'abc123-_~')));
		 
		// Work with cyrilic symbols
		$validation = new pdk_Validation($rules);
		$this->assertTrue($validation->Validate(array('test_field'=>'абв123-_')));
		$validation = new pdk_Validation($rules);
		$this->assertFalse($validation->Validate(array('test_field'=>'абв123-_~')));		
	}
}